package common.kit;

import javax.servlet.http.HttpServletRequest;

public class WebKit {
	/**
	 * 获取上下文URL全路径
	 * @param request
	 * @return
	 */
	public static String getCtx(HttpServletRequest request) {
		StringBuilder sb = new StringBuilder();
		int port = request.getServerPort();
		//80和443端口浏览器可以通过协议来识别不用表明端口
		if(port == 80 || port == 443){
			sb.append(request.getScheme()).append("://").append(request.getServerName()).append(request.getContextPath());
		}else{
			sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(port).append(request.getContextPath());
		}

		String path = sb.toString();
		return path;
	}
	
//	public static String getFullPath(HttpServletRequest request) {
//		StringBuilder sb = new StringBuilder();
//		int port = request.getServerPort();
//		if(80==port){
//			sb.append(request.getScheme()).append("://").append(request.getServerName()).append(request.getContextPath());
//		}else{
//			sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(port).append(request.getContextPath());
//		}
//		sb.append(request.getServletPath() + request.getQueryString());
//		String path = sb.toString();
//		return path;
//	}
	
	/**
	 * 获取上本机地址
	 * 
	 * @param request
	 * @return
	 */
	public static String getEditorHost(HttpServletRequest request) {
		StringBuilder sb = new StringBuilder();
		sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort());
		String path = sb.toString();
		return path;
	}
	
}
